<?php
/**
 * SearchAdsForm Form
 * 
 *  @author Redouane
 *  @since 21/04/2011
 */
class SearchAdsForm extends AdsForm{
	
	public function configure(){
		$this->useFields(array('title', 'category_id', 'subcategory_id', 'town_id'));//, 'type_id', 'is_prof'
                
		$this->widgetSchema['category_id'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Category'), 'add_empty' => false), array('onChange'=>"selectSubCategories(this.value)"));
                $this->widgetSchema['subcategory_id']= new sfWidgetFormDoctrineChoice( 
                    array(  
                            'model' => $this->getRelatedModelName('SubCategory'),
                            'query' => Doctrine_Query::create()->from('SubCategory')->where('category_id=1'),
                        )
                );
                
                 
		$this->widgetSchema['town_id'] = new sfWidgetFormDoctrineChoice(array( 
                                            'model'     => 'Town',    
                                            'order_by'  => array('num', 'asc'),    
                                            'multiple'  => false,    
                                            'add_empty' => true,
                                            'method'  => 'getFullTitle',
		));  
  		
		//$this->widgetSchema['is_prof']   = new sfWidgetFormChoice( array( 'choices'  => array(0=>'Non', 1=>'Oui'), 'multiple' => false, 'expanded' => true, ));
		$this->widgetSchema['min_price'] = new sfWidgetFormInput();
		$this->widgetSchema['max_price'] = new sfWidgetFormInput();
		
		$this->widgetSchema['town_id']->setOption('add_empty', true);
		/* Labels */
		$this->widgetSchema->setLabels(array(
	      'title'     		=> 'Titre',
	     // 'type_id'   		=> 'Transaction',
		  'category_id' 	=> 'Catégorie',
		  'subcategory_id'	=> 'Sous-catégorie',
		  'min_price' 		=> 'Prix min.',
		  'max_price' 		=> 'Prix max.',
		  'town_id'			=> 'Ville',
		  'is_prof' 		=> 'Annonce Professionnelle ?',
	    ));
	    
		/* Validators */
	    $this->validatorSchema['title']  		= new sfValidatorString(array('required' => false));
	    //$this->validatorSchema['type_id']  		= new sfValidatorString(array('required' => true));
	    $this->validatorSchema['category_id']  	= new sfValidatorString(array('required' => true));
	    $this->validatorSchema['subcategory_id']= new sfValidatorString(array('required' => true));
	    $this->validatorSchema['is_prof']		= new sfValidatorInteger(array('required' => false));
    	$this->validatorSchema['max_price'] 	= new sfValidatorInteger(array('required' => false));
    	$this->validatorSchema['min_price'] 	= new sfValidatorInteger(array('required' => false));
    	$this->validatorSchema['town_id'] 		= new sfValidatorInteger(array('required' => false));
    	
    	/* Schema */
		$this->validatorSchema['max_price']->setMessage('required', 'Veuillez renseigner le prix max.');
		$this->validatorSchema['max_price']->setMessage('invalid', 'Prix max. invalide');
		$this->validatorSchema['min_price']->setMessage('required', 'Veuillez renseigner le prix min.');
		$this->validatorSchema['min_price']->setMessage('invalid', 'Prix min. invalide');
    	
	    $this->widgetSchema->setNameFormat('search[%s]');
		$this->widgetSchema->setFormFormatterName('div');
		$this->widgetSchema->getFormFormatter()->setTranslationCatalogue('messages');
    	
	}
	
	
}